import path,{resolve} from 'path';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue';
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons';
import VitePages from 'vite-plugin-pages';
import fs from 'fs-extra';
import matter from "gray-matter";


// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
      symbolId:'icon-[dir]-[name]',
      inject:'body-last',
      customDomId:'__svg__icons__dom__'
    }),
    VitePages({
      extensions:["vue","md"],
      pageDir:"src/views",
      extendRoute(route){
        const path = resolve(__dirname.route.componment.slice(1));
        const md = fs.readFileSync(path,"utf-8");
        const { data } = matter(md);
        route.meta = Object.assign(route.meta || {},{frontmatter:data});
        return route;
      }
    })
  ],
  resolve:{
    alias:{
      //设置@指向路径 /scr 目录
      '@': resolve(__dirname, 'src')
    }
  }
})